package br.com.simora.crawler;

import javax.inject.Named;

import org.apache.log4j.Logger;

import com.google.gson.Gson;

import br.com.simora.musica.Artista;
import br.com.simora.musica.Musica;
import br.com.simora.radio.RadioEnum;
import br.com.simora.vo.KissFMVO;

@Named("kissfm")
public class KissFMCrawler extends AbstractCrawler {
	private static String URLSITE = "http://player.listenlive.co/19271/pt/songhistory?ajax";
	private static String MUSICA = "//div[@class='song']/div[@class='title']/a/text()";
	private static String ARTISTA = "//div[@class='song']/div[@class='artist']/a/text()";
	private static String URL = "http://metadata.listenlive.co/metadata/song/2f/305d72424174d972edf7c504284314ac.json";
	private static Logger logger = Logger.getLogger(KissFMCrawler.class);

	@Override
	public void recuperaInfo() {
		String url = URLSITE;
		recuperador.setUrl(url, "html");
		pagina = recuperador.getPagina();
		Gson gson = new Gson();
		String artistaNome = "";
		String musicaNome = "";
		try {
			String retorno = recuperador.recuperaItem("//div[@class='nowPlayingCard']/div[@class='song']/div[@class='title']/a/text()");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.debug(pagina.getConteudo());
		KissFMVO vo = gson.fromJson(pagina.getConteudo(), KissFMVO.class);
		if(vo != null){
			if(vo.getSong().getArtists().get(0).getName() != null){
				artista = new Artista();
				artistaNome = vo.getSong().getArtists().get(0).getName();
				artista.setNome(vo.getSong().getArtists().get(0).getName());
			}
			if(vo.getSong().getTrack().getTitle() != null){
				musica = new Musica();
				musicaNome = vo.getSong().getTrack().getTitle();
				musica.setNome(vo.getSong().getTrack().getTitle());
			}
		}
		logger.debug(artistaNome + " - " + musicaNome);
	}

	@Override
	public void setRadioNome() {
		this.radioNome = RadioEnum.kissfm.getNome();
	}

}
